home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
demos
/
telecomdemo
/
control.c
next >
Wrap
C/C++ Source or Header
|
1997-05-08
|
8KB
|
263 lines
#ifndef lint
static char SccsId[]= "@(#)control.c V1.7 3/17/95";
#endif
/*
| File name: control.c
|========================================================================
|
| Copyright (c) 1990 -- V.I. Corporation
|
|========================================================================
*/
#include "simulate.h"
#include "tlc_fundecl.h"
/*
* Constant definitions -- number of sliders to be defined and the
* input mask to be used in the window.
*/
#define NUM_SLIDERS 3
#define NORMAL_MASK ( (ULONG) V_BUTTONPRESS | V_BUTTONRELEASE | \
V_LEAVENOTIFY | V_EXPOSE | V_RESIZE | \
V_MOTIONNOTIFY | V_WINDOW_QUIT )
/*
* Local variable and function declarations.
*/
LOCAL VIEW ControlView;
LOCAL DRAWPORT ControlDrawport;
LOCAL OBJECT IterNumber;
LOCAL OBJECT Slider[NUM_SLIDERS];
#define DEF_COLORTAB (ADDRESS)NULL
/***************** Begin Function Declarations *************/
LOCAL void LoadControlView V_P_((void));
LOCAL void GetInputInfo V_P_((VIEW view));
LOCAL void GetControlVariables V_P_((VIEW view));
LOCAL BOOLPARAM PressInSlider V_P_((OBJECT location));
LOCAL void CheckForActiveSlider V_P_((OBJECT location));
/***************** End Function Declarations *************/
/*
* CreateControlScreen -- create the simulation control window and
* load the view to be displayed.
*/
void
CreateControlScreen (devname)
char *devname;
{
ControlScreen = TscOpenSet (devname, DEF_COLORTAB,
#ifdef WINNT
V_WIN32_ICON_NAME, "teleicon",
V_WINDOW_WIDTH, 230,
V_WINDOW_HEIGHT, 230,
#ifdef DOUBLE_BUFFER
V_WIN32_DOUBLE_BUFFER, YES,
#endif /* DOUBLE_BUFFER */
#else /* Not WINNT */
V_WINDOW_WIDTH, 400,
V_WINDOW_HEIGHT, 400,
V_X_EXPOSURE_BLOCK, YES,
#endif /* WINNT */
V_WINDOW_NAME, "Simulation Control",
V_WINDOW_X, 10,
V_WINDOW_Y, 10,
V_INITIAL_CURSOR,
V_END_OF_LIST);
LoadControlView ();
(VOID) TdpDraw (ControlDrawport);
(VOID) VOscWinEventMask ((ULONG) NORMAL_MASK, 0L);
}
/*
* DestroyControlScreen -- destroy the view and drawport and close the
* screen.
*/
void DestroyControlScreen
V_P_ ((void))
{
(VOID) TdpDestroy (ControlDrawport);
(VOID) TviDestroy (ControlView);
(VOID) TscClose (ControlScreen);
}
/*
* UpdateControlScreen -- update the iteration number value displayed
* in a vector text object.
*/
void UpdateControlScreen
V_P_ ((void))
{
(VOID) TdpEraseObject (ControlDrawport, IterNumber);
SetNumberString (IterNumber, (INT) SimParams.iter_number);
(VOID) TdpDrawObject (ControlDrawport, IterNumber);
}
/*
* HandleControlInput -- handle input in the control window by determining
* the type of the event and performing the correct action.
*/
void
HandleControlInput (location)
OBJECT location;
{
switch (VOloType (location))
{
case V_EXPOSE:
(VOID) TscRedraw (ControlScreen, (RECTANGLE *) NULL);
break;
case V_RESIZE:
(VOID) TscReset (ControlScreen);
break;
case V_WINDOW_QUIT:
*Control.quit_flag = 1;
break;
case V_BUTTONPRESS:
if (PressInSlider (location))
(VOID) VOscWinEventMask ((ULONG) V_ADD_TO_MASK | V_MOTIONNOTIFY, 0L);
else
(VOID) VUerHandleLocEvent (location);
break;
case V_BUTTONRELEASE:
case V_LEAVENOTIFY:
CheckForActiveSlider (location);
break;
default:
(VOID) VUerHandleLocEvent (location);
break;
}
}
/*
* LoadControlView -- load the view, get the objects and the variables,
* and create a drawport to be used.
*/
LOCAL void LoadControlView
V_P_ ((void))
{
ControlView = TviLoad (ControlViewName);
EXIT_IF_INVALID (ControlView,
"\nAborted: Control View can't be loaded\n");
GetInputInfo (ControlView);
GetControlVariables (ControlView);
IterNumber = TdrGetNamedObject (TviGetDrawing (ControlView), "IterNumber");
ControlDrawport = TdpCreateStretch (ControlScreen, ControlView,
&FullScreen, &WholeDrawing);
}
/*
* GetInputInfo -- get the sliders from the drawing and change their
* state to be inactive.
*/
LOCAL void
GetInputInfo (view)
VIEW view;
{
OBJECT drawing;
INT i;
drawing = TviGetDrawing (view);
Slider[0] = TdrGetNamedObject (drawing, "DelayTimeSlider");
Slider[1] = TdrGetNamedObject (drawing, "ErrorFactorSlider");
Slider[2] = TdrGetNamedObject (drawing, "AutoFixSlider");
for (i = 0; i < NUM_SLIDERS; i++)
(VOID) VOinState (Slider[i], INACTIVE);
}
/*
* GetControlVariables -- get the variables controlled by the input
* objects in the view, save pointers to the buffers, and set the
* initial values.
*/
LOCAL void
GetControlVariables (view)
VIEW view;
{
DATASOURCE ds;
DSVAR dsvar;
ds = TdlGetNamedDataSource (TviGetDataSourceList (view), "SimControlVars");
dsvar = TdsGetNamedDsVar (ds, "DelayTime");
Control.delay_time = (FLOAT *) TdsvGetBuffer (dsvar);
dsvar = TdsGetNamedDsVar (ds, "ErrorFactor");
Control.error_factor = (FLOAT *) TdsvGetBuffer (dsvar);
dsvar = TdsGetNamedDsVar (ds, "AutoFixDelay");
Control.autofix_delay = (FLOAT *) TdsvGetBuffer (dsvar);
dsvar = TdsGetNamedDsVar (ds, "ForceErrorFlag");
Control.force_error_flag = (SHORT *) TdsvGetBuffer (dsvar);
dsvar = TdsGetNamedDsVar (ds, "RestartFlag");
Control.restart_flag = (SHORT *) TdsvGetBuffer (dsvar);
dsvar = TdsGetNamedDsVar (ds, "PauseFlag");
Control.pause_flag = (SHORT *) TdsvGetBuffer (dsvar);
dsvar = TdsGetNamedDsVar (ds, "QuitFlag");
Control.quit_flag = (SHORT *) TdsvGetBuffer (dsvar);
*Control.delay_time = 2.0;
*Control.error_factor = 50.0;
*Control.autofix_delay = 60.0;
*Control.force_error_flag = 0;
*Control.restart_flag = 0;
*Control.pause_flag = 0;
*Control.quit_flag = 0;
}
/*
* PressInSlider -- a button press has been made in a slider. Activate
* the correct slider so that the slider bar can be dragged and allow
* the event handler to process the first pick.
*/
LOCAL BOOLPARAM
PressInSlider (location)
OBJECT location;
{
OBJECT object;
INT i;
if ((object = TloGetSelectedObject (location)))
for (i = 0; i < NUM_SLIDERS; i++)
if (object == Slider[i])
{
(VOID) VOinState (Slider[i], ACTIVE);
(VOID) VUerHandleLocEvent (location);
return YES;
}
return NO;
}
/*
* CheckForActiveSlider -- a button has been released. Check to see if
* any of the sliders are active, and if so, let the event handler deal
* with this last event and then deactivate the slider. Return the input
* mask to its original state.
*/
LOCAL void
CheckForActiveSlider (location)
OBJECT location;
{
INT i;
for (i = 0; i < NUM_SLIDERS; i++)
if (VOinState (Slider[i], (INT)NULL) == ACTIVE)
{
(VOID) VUerHandleLocEvent (location);
(VOID) VOinState (Slider[i], INACTIVE);
(VOID) VOscWinEventMask ((ULONG) NORMAL_MASK, 0L);
return;
}
}